using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class forums_controls_usercp_usercp : Controls.DataManagerUserControl
{
    protected override void ItemChanged()
    {
        if (CurrentUser != null)
        {
            mviewUser.SetActiveView(viewUser);
            Page.Title = "FSTDT Forums: " + "UserCP";
        }
        else
        {
            mviewUser.SetActiveView(viewError);
        }
    }
    protected void lnkHome_Click(object sender, EventArgs e)
    {
        mviewOptions.SetActiveView(viewDefault);
    }
    protected void lnkAvatar_Click(object sender, EventArgs e)
    {
        mviewOptions.SetActiveView(viewAvatar);
        EditAvatar1.CurrentUser = CurrentUser;
    }
    protected void lnkPassword_Click(object sender, EventArgs e)
    {
        mviewOptions.SetActiveView(viewPassword);
        ChangePassword1.CurrentUser = CurrentUser;
    }
    protected void lnkProfile_Click(object sender, EventArgs e)
    {
        mviewOptions.SetActiveView(viewProfile);
        EditProfile1.CurrentUser = CurrentUser;

    }
    protected void lnkSettings_Click(object sender, EventArgs e)
    {
        mviewOptions.SetActiveView(viewSettings);
        EditSettingsl1.CurrentUser = CurrentUser;
    }

    private void SetPrivateMessages(forums_controls_usercp_pm_privatemessages.Mailbox msgMode)
    {
        mviewOptions.SetActiveView(viewPMs);
        Privatemessages1.MsgMode = msgMode;
        Privatemessages1.CurrentUser = CurrentUser;
    }
    protected void lnkInbox_Click(object sender, EventArgs e)
    {
        SetPrivateMessages(forums_controls_usercp_pm_privatemessages.Mailbox.Inbox);
    }
    protected void lnkOutbox_Click(object sender, EventArgs e)
    {
        SetPrivateMessages(forums_controls_usercp_pm_privatemessages.Mailbox.Outbox);
    }
    protected void lnkSent_Click(object sender, EventArgs e)
    {
        SetPrivateMessages(forums_controls_usercp_pm_privatemessages.Mailbox.Sent);
    }
    protected void lnkNew_Click(object sender, EventArgs e)
    {
        mviewOptions.SetActiveView(viewPMs);
        Privatemessages1.CurrentUser = CurrentUser;
        Privatemessages1.ComposeNewMessage();
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ProcessActions();
        }
    }

    private void ProcessActions()
    {
        long id;
        if (Helpers.QueryStringHelper.TryGetInt64("readpm", out id))
        {
            SetPrivateMessages(forums_controls_usercp_pm_privatemessages.Mailbox.Inbox);

            DAL.PrivateMessage myPM = DAL.PrivateMessages.GetByIDAndUser(id, CurrentUser);
            if (myPM != null)
            {
                Privatemessages1.ShowMessage(myPM);
            }
        }
        else if (Helpers.QueryStringHelper.TryGetInt64("newpm", out id))
        {
            SetPrivateMessages(forums_controls_usercp_pm_privatemessages.Mailbox.Inbox);

            DAL.User myUser = DAL.Users.Item(id);
            if (myUser != null)
            {
                Privatemessages1.ComposeNewMessage(myUser);
            }
        }
    }
}
